<?php
/*
 * Created on Feb 5, 2009
 * @author: ANH
 * @ fileName: /modules/Form/Place.php
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 
 class node_Form_NodeType extends Zend_Form
 {
 	 protected $cName = 'node_Form_NodeType';
     protected $_noDecorator = array(
        'ViewHelper', 
        'Errors'
    );
    
    public function transformArrToText($arr)
    {
    	$text = '$config =xxxarray (' ;
    	foreach ($arr as $key=>$value)
    	{
    		if ($key != "type")
    			$text = $text . '"' . $key . '" => "' . $value . '",xxx    ';
    	} 
    	//last line
    	$text = $text . ');';
    	return $text;
    }
    
    public function cluBuild($params)
    {
    
        $this->setMethod('POST');
        $actionUrl = $this->getView()->hvnUrl(array('module' => 'node', 
        											'action' => $params['action']) , 'nocontroller');
    	$this->setAction($actionUrl);
	    
	    //name 
		$type = new Zend_Form_Element_Text('type', array('disableLoadDefaultDecorators' => true,
                                                                   'class' => 'inputText', 
                                                                   'required' => true ));
        $type->addDecorators($this->_noDecorator)
        			->addValidator('NotEmpty');
    	$this->addElement($type);
        
    	
		$metadata = new Zend_Form_Element_Textarea('metadata', array('disableLoadDefaultDecorators' => true,
                                                                   'class' => 'inputText', 'cols' => '60', 
                                                                   'required' => true));
        $metadata->addDecorators($this->_noDecorator)
        			->addValidator('NotEmpty');

        if (($params['action'] == 'new-node-type') && isset($params['isFirstTime']))
    	{
        	//if first time then populate some data for guidance
        	//Do we really need "title_label" & "body_label" ?
        	$config = array (
        		"name" => "Sample Name", //
        		"module" => "Module to use for this node", //for later hooking
        		"node_table_name" => "nodes", 
        	
        		/* category */
        		"has_category" => "1",
        		"category_table_name" => "node",
        		"root_category_id" => "0", 
        	    "category_createable" => "0", //category created by user (like blog category...)
        	
        		/* Multi language - translation */
        		"needs_translation" => "1",

        		"description" => "Some description about the node",
        		"help" => "Help text",
        		
        		"has_title" => "1", "title_label" => "",

        		"has_body" => "1", "body_label" => "",

        		"has_keywords" => "1",
        	
        		"wysiwyg" => "fckeditor", //this could be jquery_rte
        		"body_fckeditor_toolbar_set" => "Full, Comment,..", // this is probably applicable for jquery_rte
        		"body_wysisyg_width" => "600",
        		"body_wysiwyg_height" => "300",
        		"min_word_count" => "50",
        	    
        		/* weight */
	        	//	whether or not a node should have weight. In a search result
	        	// some nodes (for example, some special places) should be displayed first
	        	// Default weight should be something like 100
	        	// Using this weight we can define a weight=-1 to be sticky items...
	        	 
        		"has_weight" => 0,
        	
        		"has_thumb" => 0,
        		"has_gallery" => 0,
        	
        		"is_editable" => 1,
        		
        		
        		"db_fields" => "id,type,need_translation,language,poster_id,created,category,title,
        				body,body_summary,keywords,status,sticky,
        				promoted,views,comments,rating,number_of_ratings,metadata",
        	    "metadata_fields" => "poster_name, ..." //an array here describing list of metadata fields that may exist",
        	);
        	
        	$val = $this->transformArrToText($config);
        	$metadata->setValue($val);
    	}
    	$this->addElement($metadata);
	    
        // add the submit button
		if ($params['action'] === 'new-node-type')
    		$submit = new Zend_Form_Element_Submit('submit', array('disableLoadDefaultDecorators' => true, 
                                                           'label' => t(58) ));
      	elseif ($params['action'] === 'edit-node-type')
      		$submit = new Zend_Form_Element_Submit('submit', array('disableLoadDefaultDecorators' => true, 
                                                               'label' => t(59) ));
        
        $submit->addDecorators($this->_noDecorator);
        $this->addElement($submit);        
    }
}
?>